const APP = getApp();
Page({
	data: {
		navList: [{
				index: '1',
				c_name: '全部',
				list: [{
					goodsName: 'iPhone 15',
					url: 'https://shop.rongyiht.com/static/images/detail/iphone15.png',
					_id: '1',
					desc: '显示优惠|下单立减',
					tagList: '想分就分',
					price: 1688.00,
					discount: '原装未拆封',
					sale: 100,
					originPrice: '/期起',
					titleTag: '全新国行',
					titleTag2:'下单秒审',
					 
				}]
			},
			{
				index: '2',
				c_name: '苹果15',
				list: [{
					goodsName: 'iPhone 14',
					url: 'https://shop.rongyiht.com/static/images/detail/iphone15.png'
				}]
			},
			{
				index: '2',
				c_name: '苹果15',
			},
		], //数据
		currentIndex: 0, //左边对应的索引
		rightViewId: '', //点击事件右边的索引
	},
	getScroll(e) { //微信小程序中绑定滑动函数，每滑动一下都会触发
		let top = e.detail.scrollTop,
			h = 0,
			_this = this;


		for (let i = 0; i < this.data.navList.length; i++) {
			let dishSize = this.data.navList[i].list.length; //获取数据对应展示商品的json
			h += 38 + parseInt(dishSize / 3 * 80); //获取当前元素的高度，38是标题高度，80是元素高度

			if (top <= h) { //满足条件立刻停止循环，就会一直停留再当前索引，不满足当前就会自动到下一个菜单
				_this.setData({
					currentIndex: i
				})
				break;
			}

		}

	},
	changeMenu(e) {
		console.log(this.data.heightArr, this.data.topArr);

		this.setData({
			currentIndex: e.currentTarget.dataset.i,
			rightViewId: e.currentTarget.dataset.id
		})

	},
	/**
	 * 生命周期函数--监听页面加载
	 */

	onLoad() {

		var data = {};
		let that = this,
			banner = [];
		APP.http('post', '/index', data, function(res) {
			if (res.code == 1) {
				for (let i = 0; i < res.data.banner.length; i++) {
					banner.push({
						url: res.data.banner[i].banner_img
					})
				}
				that.setData({
					background: banner,
					project: res.data.project
				})

			} else {
				wx.showLoading({
					title: '拼命加载中',
				})
			}
		})
		 console.log('this.data',this.data)
	},
	navi_to: function(e) {
		let id = e.currentTarget.dataset.id;
		APP.jump('../detail/detail?id=' + id);
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
})
